//
//  CLBaseTextField.m
//  togetherLBS
//
//  Created by Phyllis Hu on 15/10/19.
//  Copyright (c) 2015年 celi. All rights reserved.
//

#import "CLBaseTextField.h"
#import "UIImage+Fit.h"
#import "UIView+Extension.h"

@interface  CLBaseTextField()


@end

@implementation CLBaseTextField

//- (id)initWithFrame:(CGRect)frame TextAlignment:(NSTextAlignment) TextAlignment
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 设置背景
        self.background = [UIImage resizeImage:@"garyBox"];
        
        // 设置内容 -- 垂直居中
        self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

        //空隙
        UIView *leftView = [[UIView alloc]init];
        leftView.width =  10;
        leftView.height = self.height;
//        if (TextAlignment == NSTextAlignmentCenter) {
//            leftView.width = 0;
//        }
//        [self setTextAlignment:TextAlignment];
        
        // 设置leftView的内容居中
        leftView.contentMode = UIViewContentModeCenter;
        // 设置左边的view永远显示
        self.leftViewMode = UITextFieldViewModeAlways;
        self.leftView = leftView;
        
        // 设置右边永远显示清除按钮
        self.clearButtonMode = UITextFieldViewModeAlways;
    }
    return self;
}

/**
 *  基本文本输入框(只能显示一行)
 */
//+ (instancetype)BaseInputBoxFrame:(CGRect)frame TextAlignment:(NSTextAlignment) TextAlignment
+ (instancetype)BaseInputBox
{
    return [[self alloc] init];
}

/**
 * 修改文本框的placeholder的颜色和字体大小
 */
- (void)setPlaceholderColor:(UIColor *)color font:(UIFont*)font{
    
    if (color != nil) {
        [self setValue:color forKeyPath:@"_placeholderLabel.textColor"];
    }
    if (font != nil) {
        [self setValue:font forKeyPath:@"_placeholderLabel.font"];
    }
}

@end
